% TEST_ID: LANG-EXPAND-0051
% CATEGORY: language/reflection
% 测试 varargout 变量

function test_varargout
    R1 = test_utils(1, 2); % Call with one output arguments
    assert(isequal(R1, 1));

    [R1, R2] = test_utils(2, 1); % Call with two output argument
    assert(isequal(R1, 2));
    assert(isequal(R2, 1));

    [R1, R2, R3] = test_utils(3,1,2); % Call with three output arguments
    assert(isequal(R1, 3));
    assert(isequal(R2, 1));
    assert(isequal(R3, 2));
end


function varargout = test_utils(x, y, z)
    switch nargout
        case 0
            varargout = {}; % No output if no input arguments
        case 1
            varargout{1} = x; % One output argument
        case 2
            varargout{1} = x; % First output argument
            varargout{2} = y; % Second output argument
        case 3
            varargout{1} = x; % First output argument
            varargout{2} = y; % Second output argument
            varargout{3} = z; % Third output argument
        otherwise
            error('Too many output arguments');
    end
end

